import express, { Router } from 'express'
import * as postController from './post.controller'
import { authGuard, accessControl } from '../auth/auth.middleware'
import { sort, filter, pagination } from './post.middleware'

const router: Router = express.Router()

router.get('/post/:postId', postController.show)
router.get('/post', sort, filter, pagination, postController.index)
router.post('/post', authGuard, postController.store)
router.patch(
  '/post/:postId',
  authGuard,
  accessControl({ possession: true }),
  postController.update
)
router.delete(
  '/post/:postId',
  authGuard,
  accessControl({ possession: true }),
  postController.destory
)

router.post(
  '/post/:postId/tag',
  authGuard,
  accessControl({ possession: true }),
  postController.storePostTag
)

router.delete(
  '/post/:postId/tag',
  authGuard,
  accessControl({ possession: true }),
  postController.destoryPostTag
)

export default router
